from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.versioning import QueryParameterVersioning,URLPathVersioning


"""
使用get传参方式传递版本
配置文件适合
# drf相关配置以后编写在这里
REST_FRAMEWORK = {
    "VERSION_PARAM": "v",
    "DEFAULT_VERSION": "v1",
    "ALLOWED_VERSIONS": ["v1", "v2", "v3"],
    "DEFAULT_VERSIONING_CLASS":"rest_framework.versioning.QueryParameterVersioning",   # 所有都用这个版本管理
}
"""
class UserView_GET(APIView):

    versioning_class = QueryParameterVersioning

    def get(self, request, *args, **kwargs):
        print(request.data)
        parms = request.query_params
        # print(parms["version"],type(parms))
        print(request.version)
        return Response({"code": 1000, "data": "xxx"})

    def post(self, request, *args, **kwargs):
        return Response({"code": 1000, "data": "xxx"})




"""
使用URL方式传递版本
配置文件适合：
# drf相关配置以后编写在这里
REST_FRAMEWORK = {
    # "VERSION_PARAM": "v",
    # "DEFAULT_VERSION": "v1",
    "ALLOWED_VERSIONS": ["v1", "v2", "v3"],
    "DEFAULT_VERSIONING_CLASS":"rest_framework.versioning.QueryParameterVersioning",   # 所有都用这个版本管理
}

"""
class UserView_URL(APIView):

    versioning_class = URLPathVersioning

    def get(self, request, *args, **kwargs):
        print(request.data)
        parms = request.query_params
        # print(parms["version"],type(parms))
        print(request.version)
        return Response({"code": 1000, "data": "xxx"})

    def post(self, request, *args, **kwargs):
        return Response({"code": 1000, "data": "xxx"})





